import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
import {BaseService} from '../../../shared/service/base.service';
import {ApiUrl} from '../../../config/api-url';
import {AliApplymentStateEnum} from '../../../enums/ali-applyment-state.enum';
import {ApplymentStateEnum} from '../../../enums/applyment-state.enum';

declare let $;

@Component({
  selector: 'app-authentication-status',
  templateUrl: './authentication-status.component.html',
  styleUrls: ['./authentication-status.component.less']
})
export class AuthenticationStatusComponent implements OnInit {
// 模态框显隐
  @Input()
  isVisible = false;
  @Input()
  feedback: any;
  // 父子互传值
  @Output()
  emit: EventEmitter<any> = new EventEmitter();
  @Input()
  merchantList: any = [];
  // 提交时提交按钮是否加载中
  isOkLoading: any;
  nzLoading = false;
  aliApplymentStateEnum = {
    AUDITING: AliApplymentStateEnum.AUDITING,
    CONTACT_PROCESSING: AliApplymentStateEnum.CONTACT_PROCESSING,
    CONTACT_CONFIRM: AliApplymentStateEnum.CONTACT_CONFIRM,
    LEGAL_CONFIRM: AliApplymentStateEnum.LEGAL_CONFIRM,
    AUDIT_PASS: AliApplymentStateEnum.AUDIT_PASS,
    AUDIT_REJECT: AliApplymentStateEnum.AUDIT_REJECT,
    AUDIT_FREEZE: AliApplymentStateEnum.AUDIT_FREEZE,
    CANCELED: AliApplymentStateEnum.CANCELED,
  };
  applymentStateEnum = {
    APPLYMENT_STATE_WAITTING_FOR_AUDIT: ApplymentStateEnum.APPLYMENT_STATE_WAITTING_FOR_AUDIT,
    APPLYMENT_STATE_EDITTING: ApplymentStateEnum.APPLYMENT_STATE_EDITTING,
    APPLYMENT_STATE_WAITTING_FOR_CONFIRM_CONTACT: ApplymentStateEnum.APPLYMENT_STATE_WAITTING_FOR_CONFIRM_CONTACT,
    APPLYMENT_STATE_WAITTING_FOR_CONFIRM_LEGALPERSON: ApplymentStateEnum.APPLYMENT_STATE_WAITTING_FOR_CONFIRM_LEGALPERSON,
    APPLYMENT_STATE_PASSED: ApplymentStateEnum.APPLYMENT_STATE_PASSED,
    APPLYMENT_STATE_REJECTED: ApplymentStateEnum.APPLYMENT_STATE_REJECTED,
    APPLYMENT_STATE_FREEZED: ApplymentStateEnum.APPLYMENT_STATE_FREEZED,
    APPLYMENT_STATE_CANCELED: ApplymentStateEnum.APPLYMENT_STATE_CANCELED,
  };
  constructor(private fb: FormBuilder, private baseService: BaseService) { }

  ngOnInit(): void {
  }
  base64(wxQrcode) {
    return `data:image/png;base64,${wxQrcode}`;
  }
  ngOnChanges() {
    this.nzLoading=false;

  }
  payCompanyCodeLoad(){
    this.baseService.post(ApiUrl.MerchantUrl + '/findAuthenticationStatusById', {id: this.feedback.id}).subscribe(res => {
        this.merchantList = res.data;
        this.nzLoading=false;
        let  thet = this;
        setTimeout(function(){
          thet.renderCode();
        }, 500);
    });
  }
  renderCode(){
    this.merchantList.forEach(item => {
      $('#qrcode' + item.certificationChannels).html('');
      $('#qrcode' + item.certificationChannels).qrcode({width: 120, height: 120, text: item.channelCode});
    });
  }
  refresh(){
    this.nzLoading=true;
    this.payCompanyCodeLoad();
  }
  // 取消
  handleCancel() {
    this.isVisible = false;
    this.emit.emit(this.isVisible);
  }
}
